<?php
class Managecategory_Data_Editaction {
	
	private $database;
	private $secure;
	
	public function __construct(){
		$this->secure = new Core_Data_Secure();
		$this->database = new Core_Driver_MysqlImproved();
	}
	
	public function updateValues(array $postVars){
		$postVars = $this->secure->parseData($postVars);
		
		$editCategory = $postVars['editCategory'];
		$name = $postVars['name'];
		$accessLevel = $postVars['privileges'];
		$title = $postVars['title'];
		$description = $postVars['description'];
		$keywords = $postVars['keywords'];
		
		$this->updateCategorySettings($editCategory, $name, $accessLevel);
		$this->updateMetaCategory($editCategory, $name, $title, $description, $keywords);
		echo '<meta http-equiv="Refresh" content="0;url='.SERVER_ROOT.'?managecategory">';
	}
	
	private function updateMetaCategory($editCategory, $name, $title, $description, $keywords){
		$this->database->connect();
		$editCategory = $this->database->escape($editCategory);
		$name = $this->database->escape($name);
		$title = $this->database->escape($title);
		$description = $this->database->escape($description);
		$keywords = $this->database->escape($keywords);
		
		$this->database->prepare(
			"update category_meta_values set category_name = '$name', category_meta_title = '$title', category_meta_keywords = '$keywords', category_meta_description = '$description' where category_name = '$editCategory';"
		);
		$this->database->query();
		$this->database->dataOperations();
		
	}
	
	private function updateCategorySettings($editCategory, $name, $accessLevel){
		$this->database->connect();
		$editCategory = $this->database->escape($editCategory);
		$name = $this->database->escape($name);
		$accessLevel = $this->database->escape($accessLevel);
		$this->database->prepare(
			"
				update category_settings set category_name = '$name', category_access_level = '$accessLevel' where category_name = '$editCategory';
				"
		);
		$this->database->query();
		$this->database->dataOperations();
	}
	
}